package com.nenude.corejava.ch10;

import java.util.Deque;
import java.util.LinkedList;

public class LinkedListClass {

	public static void main(String[] args) {
		// LinkedList实现了多种数据结构
		//实现了(双端)链表结构，队列结构

		//队列结构：先进先出，后进后出
		//LinkedList<Computer> linkedList=new LinkedList<Computer>();
		
		//Deque:双端队列
		Deque<Computer> linkedList=new LinkedList<Computer>();
		//双端队列：从尾部加，从头部取（成对出现）
		linkedList.addLast(new Computer("HP1",8000));
		linkedList.addLast(new Computer("HP2",8000));
		linkedList.addLast(new Computer("HP3",8000));
		linkedList.addLast(new Computer("HP4",8000));
		linkedList.addLast(new Computer("HP5",8000));
		linkedList.addLast(new Computer("HP6",8000));
		linkedList.addLast(new Computer("HP7",8000));
		
		//取出数据并删除
		Computer computer=null;
		while ((computer=linkedList.pollFirst())!=null) {
			System.out.println(computer);
		}
		
		System.out.println("++++++++++++++++++++++++++");
		linkedList.addFirst(new Computer("HP1",8000));
		linkedList.addFirst(new Computer("HP2",8000));
		linkedList.addFirst(new Computer("HP3",8000));
		linkedList.addFirst(new Computer("HP4",8000));
		linkedList.addFirst(new Computer("HP5",8000));
		linkedList.addFirst(new Computer("HP6",8000));
		linkedList.addFirst(new Computer("HP7",8000));
		
		while ((computer=linkedList.pollLast())!=null) {
			System.out.println(computer);
		}
		
		
	}

}
